﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ninject;
using Ninject.Syntax;
using Zatify.Domain.Abstract;
using Zatify.Domain.Concrete;
using Zatify.WebUI.Infrastructure.Filters;
using Zatify.WebUI.Infrastructure.Absrtact;
using Zatify.WebUI.Infrastructure.Concrete;

namespace Zatify.WebUI.Infrastructure
{
    //internal class SiteModule : Ninject.Modules.NinjectModule
    //{
    //    public override void Load()
    //    {
    //        Bind<IZatifyRepository>().To<ZatifyRepository>();

    //        this.BindFilter<ZatifyAuthorizeFilter>(FilterScope.Controller, 0)
    //            .WhenControllerType<ZatifyAuthorizeAttribute>();


    //    }
    //}
    public class NinjectDependencyResolver : IDependencyResolver
    {
        private IKernel kernel;

        public NinjectDependencyResolver()
        {
            kernel = new StandardKernel();
            AddBindings();
        }

        public object GetService(Type serviceType)
        {
            return kernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return kernel.GetAll(serviceType);
        }

        public IBindingToSyntax<T> Bind<T>()
        {
            return kernel.Bind<T>();
        }

        private void AddBindings()
        {
            Bind<IZatifyRepository>().To<ZatifyRepository>();
            Bind<IZatifyAuthProvider>().To<ZatifyFormsAuthenticateProvider>();
            Bind<IPasswordRecoveryService>().To<ZatifyPasswordRecoverySender>();
            Bind<IZatifyEmailSender>().To<ZatifyEmailSender>();
            Bind<IDistanceCalculator>().To<DistanceCalculator>();
        }
    }
}